/*
 * dev_prv.h
 */
#ifndef DEV_PRV_H
#define DEV_PRV_H

#include "stdint.h"
#include "string.h"
#include "rtos.h"
#include "hal_drv.h"

typedef uint32_t dev_addr_t;

#define dev_os_delay_ms(ms)  os_delay_ms(ms)
#define dev_err(...)

#define dev_check_p(p, content)     do{ \
                                        if(p==NULL) \
                                        {\
                                            dev_err(content);\
                                            return;\
                                        }\
                                    }while(0)

typedef struct {
    dev_addr_t handle_address;
    dev_addr_t bus_adress;
}device_base_t;
                           
static inline void dev_connect(void *device, void *handle, void *bus)
{
    device_base_t *dev = (device_base_t *)device;
    dev->handle_address = (dev_addr_t)handle;
    dev->bus_adress = (dev_addr_t)bus;
};

typedef struct
{
    uint8_t (*rw_byte)(void *handle, uint8_t send_byte);
    void (*enable)(void *handle, uint8_t enable);
}spi_general_bus_t;

typedef struct
{
    void (*adjust)(void *handle, uint16_t level);
    void (*init)(void *handle, uint16_t level_max, uint32_t freq);
    void (*set_freq)(void *handle, uint16_t freq);
}general_out_bus_t;

typedef struct
{
    uint16_t (*read)(void *handle, uint8_t *buff, uint16_t buff_size, uint16_t len);
    uint16_t (*write)(void *handle, uint8_t *buff, uint16_t len);
    void (*enable)(void *handle, uint8_t enable);
}general_bus_t;

typedef struct
{
    uint8_t (*read)(void *handle);
}key_bus_t;

#endif /* DEV_PRV_H */
